//
//  YGCategoryView.m
//  yunGuang
//
//  Created by IOS on 2022/5/7.
//  Copyright © 2022 Brezze GWG. All rights reserved.
//

#import "YGCategoryView.h"

@interface YGCategoryView ()

@end

@implementation YGCategoryView


@end

#pragma mark - YGCategoryCustomView --

#define kMarginItem 4

@interface YGCategoryCustomView ()
{
    UIView *_itemBGView;
    UIView *_itemView;
    CGFloat _item_w;
    CGFloat _margin_x;
    UIView *_swView;
}


@end

@implementation YGCategoryCustomView

//- (instancetype)initWith:(NSArray *)titles isFullWidth:(BOOL)isFullWidth
//{
//    self = [super init];
//    if (self) {
//        _titles = titles;
//        _isFullWidth = isFullWidth;
//        _margin_x = 0;
//        [self setUI];
//    }
//    return self;
//}

- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles {
    
    self = [super initWithFrame:frame];
    if (self) {
        _titles = titles;
        _margin_x = 0;
        [self setUI];
    }
    return self;
}

- (void)itemClick:(UIButton *)btn {
    
    
    NSInteger index = btn.tag - 1000;
    
    if(self.currIndex == index) return;
    
    [self itemMove:index];
//    self.currIndex = index;
//    CGFloat item_width = (self.mj_w) / _titles.count;
//    [UIView animateWithDuration:0.35 animations:^{
//        if (index == 0) {
//            self->_itemView.transform = CGAffineTransformMakeRotation(0);
//        }else {
//            self->_itemView.transform = CGAffineTransformMakeTranslation(item_width * index , 0);
//        }
//        
//    }];
//    
//    for (int i = 0; i < self.titles.count; i++) {
//        UIButton *btnn = [self viewWithTag:1000 + i];
//        btnn.selected = btnn.tag == btn.tag;
//        UIFont *font = btnn.tag == btn.tag ? [UIFont fontS:12] : [UIFont fontM:12];
//        btnn.titleLabel.font = font;
//    }
//    
//    if (self.itemSeletedBlock) {
//        self.itemSeletedBlock(index);
//    }
////    [self itemSelectHiddenLine:index];
}

- (void)itemMove:(NSInteger)index {
    
    self.currIndex = index;
    CGFloat item_width = (self.mj_w) / _titles.count;
    [UIView animateWithDuration:0.35 animations:^{
        if (index == 0) {
            self->_itemView.transform = CGAffineTransformMakeRotation(0);
        }else {
            self->_itemView.transform = CGAffineTransformMakeTranslation(item_width * index , 0);
        }
        
    }];
    
    for (int i = 0; i < self.titles.count; i++) {
        UIButton *btnn = [self viewWithTag:1000 + i];
        btnn.selected = (btnn.tag - 1000) == index;
        UIFont *font = (btnn.tag - 1000) == index ? [UIFont fontS:12] : [UIFont fontM:12];
        btnn.titleLabel.font = font;
    }
    
    if (self.itemSeletedBlock) {
        self.itemSeletedBlock(index);
    }
    
}


- (void)itemSelectHiddenLine:(NSInteger)index {
    
    for (int i = 0; i < self.titles.count - 1; i++) {
        
        UIView *line = [_itemBGView viewWithTag:900 + i];
        line.hidden = NO;
    }
    //第一个
    if (index == 0) {
        [self hiddenLine:0];
        return;
    }
    // 最后
    if (index == self.titles.count - 1) {
        [self hiddenLine:index - 1];
        return;
    }
    // 中间
    [self hiddenLine:index - 1];
    [self hiddenLine:index];
}

- (void)hiddenLine:(NSInteger)index {
    UIView *line = [_itemBGView viewWithTag:900 + index];
    line.hidden = YES;
}


- (void)setSelColor:(UIColor *)selColor {
    _selColor = selColor;
    for (int i = 0; i < _titles.count; i++) {
        
        UIButton *btn = [self viewWithTag:i + 1000];
        [btn setTitleColor:selColor forState:UIControlStateSelected];
    }
}

- (void)setDefColor:(UIColor *)defColor {
    _defColor = defColor;
    for (int i = 0; i < _titles.count; i++) {
        UIButton *btn = [self viewWithTag:i + 1000];
        [btn setTitleColor:defColor forState:UIControlStateNormal];
    }
}

- (void)setItemBGColor:(UIColor *)itemBGColor {
    _itemBGColor = itemBGColor;
    _swView.backgroundColor = itemBGColor;
}

- (void)br_itemAddShadow {
    // Shadow Code
    _itemView.layer.shadowColor = [UIColor colorWithRed:109/255.0 green:209/255.0 blue:0/255.0 alpha:0.26].CGColor;
    _itemView.layer.shadowOffset = CGSizeMake(0,3);
    _itemView.layer.shadowRadius = 5;
    _itemView.layer.shadowOpacity = 1;
}


#pragma mark - UI --
- (void)setUI {
    
    self.backgroundColor  = UIColor.clearColor;
//    self.layer.cornerRadius = self.mj_h / 2.0;
    self.layer.masksToBounds = YES;
    
    
    UIView *itemBGView = [[UIView alloc] init];
    itemBGView.layer.cornerRadius = 10;
    itemBGView.layer.masksToBounds = YES;
    itemBGView.backgroundColor = kColorBGEC;
    [self addSubview:itemBGView];
    [itemBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(_margin_x);
        make.right.offset(-_margin_x);
        make.height.mas_equalTo(44);
        make.top.offset(0);
    }];
    _itemBGView = itemBGView;
    
//    _item_w = (self.mj_w - kMarginItem * (_titles.count + 1)) /  _titles.count;
//    self.mj_w = kScreenWidth - 122;
    CGFloat item_width = (self.mj_w) / _titles.count;
    _item_w = item_width - kMarginItem * 2;
    UIView *itemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _item_w, 36)];
    itemView.backgroundColor = UIColor.clearColor;
    [self addSubview:itemView];
    [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.width.mas_equalTo(item_width);
        make.height.mas_equalTo(44);
        make.centerY.equalTo(itemBGView).offset(0);
    }];
    _itemView = itemView;
//    // Shadow Code
//    itemView.layer.shadowColor = [UIColor colorWithRed:18/255.0 green:149/255.0 blue:255/255.0 alpha:0.26].CGColor;
//    itemView.layer.shadowOffset = CGSizeMake(0,3);
//    itemView.layer.shadowRadius = 5;
//    itemView.layer.shadowOpacity = 1;
    
    UIView *swView = [[UIView alloc] initWithFrame:CGRectMake(kMarginItem, 4, _item_w, 36)];
    swView.layer.cornerRadius = 6;
    swView.layer.masksToBounds = YES;
    swView.backgroundColor = UIColor.whiteColor;
    [itemView addSubview:swView];
    [swView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(4);
        make.width.mas_equalTo(_item_w);
        make.height.mas_equalTo(36);
        make.centerY.offset(0);
    }];
    _swView = swView;
    
    CGFloat btn_w = item_width;
    UIButton *lastBtn;
    for (int i = 0; i < _titles.count; i++) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:_titles[i] forState:UIControlStateNormal];
        [btn setTitleColor:UIColorMakeWithHex(@"#AAAAAC") forState:UIControlStateNormal];
        [btn setTitleColor:kColorMain forState:UIControlStateSelected];
        btn.tag = 1000 + i;
        btn.frame = CGRectMake(btn_w * i, 0, btn_w, self.mj_h);
        btn.titleLabel.font = [UIFont fontM:12];
        btn.selected = i == 0; // 默认第一个
        btn.titleLabel.numberOfLines = 2;
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 4);
        [self addSubview:btn];
        [btn addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            if (i == 0) {
                make.left.equalTo(itemBGView).offset(0);
            }else {
                make.left.equalTo(lastBtn.mas_right).offset(0);
            }
            make.width.mas_equalTo(btn_w);
            make.height.mas_equalTo(36);
            make.centerY.equalTo(itemBGView).offset(0);
        }];
        lastBtn = btn;
    }
//    for (int i = 0; i < self.titles.count - 1; i++) {
//        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(_item_w * (i + 1), 8, 0.5, 20)];
//        line.backgroundColor = GGColor192;
//        line.tag = 900 + i;
//        line.hidden = i == 0;
//        [itemBGView insertSubview:line atIndex:0];
//    }
    
}

@end
#pragma mark - YGCategoryNumView --
@interface YGCategoryNumView ()
{
    UIView *_lineView;
    
    CGFloat _item_w;
    CGFloat _margin_x;
   
}

@end

@implementation YGCategoryNumView

- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles {
    
    self = [super initWithFrame:frame];
    if (self) {
        _titles = titles;
        
        [self setUI];
    }
    return self;
}

- (void)itemClick:(UITapGestureRecognizer *)item {
    
    NSInteger index = item.view.tag - 400;
    
    if(self.currIndex == index) return;
    
    self.currIndex = index;
    CGFloat item_x = _item_w * index;
    [UIView animateWithDuration:0.25 animations:^{
        if (index == 0) {
            self->_lineView.transform = CGAffineTransformMakeRotation(0);
        }else {
            self->_lineView.transform = CGAffineTransformMakeTranslation(item_x , 0);
        }
        
    }];
    
    for (int i = 0; i < _titles.count; i++) {
//        BRMTitleView *titleView = [self viewWithTag:400 + i];
//        UIColor *color = i == index ? kColorMain : UIColorMakeWithHex(@"#889DBB");
//        titleView.stackView.titleColor = color;
//        titleView.stackView.textColor = color;
    }
    
    if (self.itemSeletedBlock) {
        self.itemSeletedBlock(index);
    }
}

- (void)br_titleView:(NSString *)text by:(NSInteger)index {
//    BRMTitleView *titleView = [self viewWithTag:400 + index];
//    titleView.stackView.text = text;
}

- (void)setTitleLNumLine:(NSInteger)titleLNumLine {
    _titleLNumLine = titleLNumLine;
    
    for (int i = 0; i < _titles.count; i++) {
//        BRMTitleView *titleView = [self viewWithTag:400 +i];
//        titleView.stackView.titleL.numberOfLines = titleLNumLine;
    }
}


#pragma mark - UI --
- (void)setUI {
    
    __block CGFloat w = kScreenWidth / _titles.count;
    _item_w = w;
    _margin_x = w / 2. - 22.;
    for (int i = 0; i < _titles.count; i++) {
        
//        BRMTitleView *titleView = [[BRMTitleView alloc] init];
//        titleView.backgroundColor = UIColor.whiteColor;
//        UIColor *color = i == 0 ? kColorMain : UIColorMakeWithHex(@"#889DBB");
//        titleView.stackView.titleColor = color;
//        titleView.stackView.textColor = color;
//        titleView.stackView.titleL.font = [UIFont br_fontM:10];
//        titleView.stackView.textL.font = [UIFont br_fontB:14];
//        titleView.stackView.titleL.textAlignment = NSTextAlignmentCenter;
//        titleView.stackView.textL.textAlignment = NSTextAlignmentCenter;
//        titleView.stackView.title = _titles[i];
//        titleView.stackView.text = @"0";
//        titleView.tag = i + 400;
//        [titleView br_updateMarginX:0];
//        [self addSubview:titleView];
//        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.bottom.offset(0);
//            make.left.offset(i * w);
//            make.width.mas_equalTo(w);
//        }];
        
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemClick:)];
//        [titleView addGestureRecognizer:tap];
    }
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = kColorMain;
    line.layer.cornerRadius = 2;
    line.layer.masksToBounds = YES;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(_margin_x);
        make.height.mas_equalTo(4);
        make.bottom.offset(2);
        make.width.mas_equalTo(44);
    }];
    _lineView = line;
    self.layer.masksToBounds = YES;
}

@end

#pragma mark - YGCategoryNum2View --
@interface YGCategoryNum2View ()
{
    UIView *_lineView;
    
    CGFloat _item_w;
    CGFloat _margin_x;
   
    UIScrollView *_sView;
}

@end

@implementation YGCategoryNum2View

- (instancetype)initWith:(CGFloat)itemW titles:(NSArray *)titles {
    
    self = [super init];
    if (self) {
        _titles = titles;
        
        if (itemW == 0) {
            _item_w = kScreenWidth / _titles.count;
        }else {
            _item_w = itemW;
            if (kScreenWidth / _titles.count > itemW) {
                _item_w = kScreenWidth / _titles.count;
                
            }
        }
        [self setUI];
    }
    return self;
}

- (void)itemClick:(UITapGestureRecognizer *)item {
    
    NSInteger index = item.view.tag - 500;
    
    if(self.currIndex == index) return;
    
    [self itemMove:index];
    
    if (self.itemSeletedBlock) {
        self.itemSeletedBlock(index);
    }
}

- (void)itemMove:(NSInteger)index {
    CGFloat offsetX = _item_w * index;
//    CGFloat currX = _sView.contentOffset.x;
    __block CGFloat toX = offsetX + _item_w - kScreenWidth;
    if (toX > 0) {
        if (index != _titles.count - 1) {
            toX += (_item_w / 2.0);
        }
        [self->_sView setContentOffset:CGPointMake(toX, 0) animated:YES];
    }else {
        [self->_sView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
    [self br_showShadow:index + 1 == _titles.count];
    
//    NSLog(@"[%.2f]-[%.2f]",offsetX,currX);
//    [_sView setContentOffset:CGPointMake(_item_w * index, 0)];
    _currIndex = index;
    CGFloat item_x = _item_w * index;
    [UIView animateWithDuration:0.25 animations:^{
        if (index == 0) {
            self->_lineView.transform = CGAffineTransformMakeRotation(0);
        }else {
            self->_lineView.transform = CGAffineTransformMakeTranslation(item_x , 0);
        }

    }];
    
    for (int i = 0; i < _titles.count; i++) {
//        BRMTitle2View *titleView = [self viewWithTag:500 + i];
//        UIColor *color = i == index ? kColorMain : kColorTitle888;
//        titleView.titleColor = color;
//        titleView.textColor = color;
//        titleView.textL.font = i == index ? [UIFont br_fontB:14] : [UIFont br_fontS:14] ;
    }
}

- (void)setCurrIndex:(NSInteger)currIndex {
    _currIndex = currIndex;
    
    [self itemMove:currIndex];
}

- (void)br_setCurrIndex:(NSInteger)index {
    [self itemMove:index];
}

- (void)br_showShadow:(BOOL)hidden {
    if (self.shadowView.superview) {
        self.shadowView.hidden = hidden;
    }
}

- (void)br_titleView:(NSString *)text by:(NSInteger)index {
//    BRMTitle2View *titleView = [self viewWithTag:500 + index];
//    titleView.text = text;
}

- (void)setTitleLNumLine:(NSInteger)titleLNumLine {
    _titleLNumLine = titleLNumLine;
    
    for (int i = 0; i < _titles.count; i++) {
//        BRMTitle2View *titleView = [self viewWithTag:500 +i];
//        titleView.titleL.numberOfLines = titleLNumLine;
    }
}


#pragma mark - UI --
- (void)setUI {
    
    UIScrollView *sView = [[UIScrollView alloc] init];
    sView.showsHorizontalScrollIndicator = NO;
    [self addSubview:sView];
    [sView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    UIView *contView = [[UIView alloc] init];
    [sView addSubview:contView];
    [contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
        make.height.mas_equalTo(44);
    }];
    _sView = sView;
    CGFloat width = _titles.count * _item_w;
    sView.contentSize = CGSizeMake(width, 0);
    __block CGFloat w = _item_w;
    _margin_x = w / 2. - 22.;
    for (int i = 0; i < _titles.count; i++) {
        
//        BRMTitle2View *titleView = [[BRMTitle2View alloc] init];
//        titleView.backgroundColor = UIColor.whiteColor;
//        UIColor *color = i == 0 ? kColorMain : kColorTitle888;
//        titleView.titleColor = color;
//        titleView.textColor = color;
//        titleView.titleL.font = [UIFont br_fontM:10];
//        titleView.textL.font = i == 0 ? [UIFont br_fontB:14] : [UIFont br_fontS:14];
//        titleView.title = _titles[i];
//        titleView.text = @"0";
//        titleView.tag = i + 500;
//        [contView addSubview:titleView];
//        [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.bottom.offset(0);
//            make.left.offset(i * w);
//            make.width.mas_equalTo(w);
//            if (i == _titles.count - 1) {
//                make.right.offset(0);
//            }
//        }];
//
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemClick:)];
//        [titleView addGestureRecognizer:tap];
    }
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = kColorMain;
    line.layer.cornerRadius = 2;
    line.layer.masksToBounds = YES;
    [contView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(_margin_x);
        make.height.mas_equalTo(4);
        make.bottom.offset(2);
        make.width.mas_equalTo(44);
    }];
    _lineView = line;
//    self.layer.masksToBounds = YES;
    if ( width > kScreenWidth) [self addSubview:self.shadowView];
//    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//    }];
}

- (UIView *)shadowView {
    
    if (_shadowView == nil) {
        _shadowView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth - 22, 0, 22, 44)];
        _shadowView.userInteractionEnabled = NO;
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0, 0, 22, 44);
        gl.startPoint = CGPointMake(0.50, 0.50);
        gl.endPoint = CGPointMake(0.00, 0.50);
        gl.colors = @[
        (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.00].CGColor,
        (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.00].CGColor,
        ];
        gl.locations = @[@(0.0),@(1.f)];
        [_shadowView.layer addSublayer:gl];
    }
    return _shadowView;
}

@end

#pragma mark - ----- --
@interface YGCategoryBtnView()
{
    NSArray *_titles;
    UIColor *_selColor;
    UIColor *_color;
    CGFloat _cornerRadius;
}
@end

@implementation YGCategoryBtnView

- (instancetype)initWithTitles:(NSArray *)titles
{
   
    return [self initWithTitles:titles cornerRadius:18];
}

- (instancetype)initWithTitles:(NSArray *)titles cornerRadius:(CGFloat)radius;
{
    self = [super init];
    if (self) {
        _cornerRadius = radius;
        _titles = titles;
        _selColor = UIColorMakeWithHex(@"#cfafe3");
        _color = UIColor.whiteColor;
        [self setUI];
    }
    return self;
}

- (instancetype)initWithLabelTitles:(NSArray *)titles
{
    self = [super init];
    if (self) {
        _titles = titles;
        _selColor = UIColorMakeWithHex(@"#cfafe3");
        _color = UIColor.whiteColor;
        [self setUIWhit:titles];
    }
    return self;
}

- (void)itemClick:(QMUIButton *)btn {
    
    if (btn.isSelected) return;
    NSInteger index = btn.tag - 500;
    
    for (int i = 0; i < _titles.count; i++) {
        QMUIButton *btn = [self viewWithTag:i + 500];
        btn.selected = i == index;
        btn.layer.borderColor = i == index ?  _selColor.CGColor : _color.CGColor;
    }
    
    if (self.itemSeletedBlock) self.itemSeletedBlock(index);
    
}


#pragma mark - UI --
- (void)setUI {
    UIStackView *stack = [[UIStackView alloc] init];
    stack.spacing = 6;
    stack.distribution = UIStackViewDistributionFillEqually;
    [self addSubview:stack];
    [stack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.top.bottom.offset(0);
//        make.centerY.offset(0);
//        make.height.mas_equalTo(36)
    }];
    
    for (int i = 0; i < _titles.count; i++) {
        UIView *bgV = [[UIView alloc] init];
        [stack addArrangedSubview:bgV];
        QMUIButton *btn = [[QMUIButton alloc] init];
        [btn setTitle:_titles[i] forState:UIControlStateNormal];
        [btn setTitleColor:kColorTitle88B forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        [btn jk_setBackgroundColor:kColorBGF5 forState:UIControlStateNormal];
        [btn jk_setBackgroundColor:kColorMain forState:UIControlStateSelected];
        btn.layer.cornerRadius = _cornerRadius;
        btn.layer.masksToBounds = YES;
        btn.layer.borderWidth = 2;
        btn.layer.borderColor = i == 0 ?  _selColor.CGColor : _color.CGColor;
        btn.selected = i == 0;
        UIFont *font =  i == 0 ? [UIFont br_fontS:12] : [UIFont br_fontM:12] ;
        btn.titleLabel.font = font;
        btn.titleLabel.numberOfLines = 2;
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//        [stack addArrangedSubview:btn];
        btn.tag = 500 + i;
        [btn addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgV addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(2);
            make.right.bottom.offset(-2);
        }];
    }
}

- (void)setUIWhit:(NSArray *)titles {
    
    UIStackView *stack = [[UIStackView alloc] init];
    stack.spacing = 8;
    stack.distribution = UIStackViewDistributionFillEqually;
    [self addSubview:stack];
    [stack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.right.offset(-16);
        make.top.bottom.offset(0);
//        make.centerY.offset(0);
//        make.height.mas_equalTo(36)
    }];
    
    for (int i = 0; i < _titles.count; i++) {
        UIView *bgV = [[UIView alloc] init];
        [stack addArrangedSubview:bgV];
        QMUIButton *btn = [[QMUIButton alloc] init];
//        [btn setTitle:_titles[i] forState:UIControlStateNormal];
//        [btn setTitleColor:kColorTitle888 forState:UIControlStateNormal];
//        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        [btn jk_setBackgroundColor:kColorBGF5 forState:UIControlStateNormal];
        [btn jk_setBackgroundColor:kColorMain forState:UIControlStateSelected];
        btn.layer.cornerRadius = 22;
        btn.layer.masksToBounds = YES;
        btn.layer.borderWidth = 2;
        btn.layer.borderColor = i == 0 ?  _selColor.CGColor : _color.CGColor;
        btn.selected = i == 0;
        UIFont *font =  i == 0 ? [UIFont br_fontS:13] : [UIFont br_fontM:13] ;
        btn.titleLabel.font = font;
//        [stack addArrangedSubview:btn];
        btn.tag = 500 + i;
        [btn addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgV addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(2);
            make.right.bottom.offset(-2);
        }];
        UIColor *tColor = i == 0 ? UIColor.whiteColor : kColorTitle88B;
        QMUILabel *titleL = [BRToolsView br_label:titles[i] textColor:tColor font:font];
        [btn addSubview:titleL];
    }
    
}


@end
